﻿using Ace;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Chloe.Entities;
using Chloe.Application.Interfaces.Bike;
using Chloe.Application.Models.Activity;

namespace Chloe.Application.Implements.Bike
{
    public class ActivityAppService : AdminAppService, IActivityAppService
    {
        public List<Bike_Activity> GetActivitys(string keyword)
        {
            var q = this.DbContext.Query<Bike_Activity>().FilterDeleted().WhereIfNotNullOrEmpty(keyword, a => a.Name.Contains(keyword) /*|| a.EnCode.Contains(keyword)*/);
            q = q.OrderByDesc(a => a.Date);

            return q.ToList();
        }
        public List<SimpleActivityModel> GetSimpleModels()
        {
            var q = this.DbContext.Query<Bike_Activity>().FilterDeleted();
            q = q.OrderBy(a => a.Date);

            return q.Select(a => new SimpleActivityModel() { Id = a.Id, Name = a.Name }).ToList();
        }

        //public List<SimpleActivityModel2> GetSimpleModels2()
        //{
        //    var q = this.DbContext.Query<Bike_Activity>().FilterDeleted();
        //    q = q.OrderBy(a => a.Date);

        //    return q.Select(a => new SimpleActivityModel2() { Id = a.Id, Text = a.Name }).ToList();
        //}

        public void Add(AddActivityInput input)
        {
            input.Validate();
            Bike_Activity entity = this.CreateEntity<Bike_Activity>();

            entity.Name = input.Name;
            entity.Date = input.Date;
            entity.People = input.People;
            entity.Description = input.Description;

            this.DbContext.Insert(entity);
        }
        public void Update(UpdateActivityInput input)
        {
            input.Validate();

            this.DbContext.Update<Bike_Activity>(a => a.Id == input.Id, a => new Bike_Activity()
            {
                Name = input.Name,
                Date = input.Date,
                People = input.People,
                Description = input.Description,
            });
        }
        public void Delete(string id)
        {
            this.SoftDelete<Bike_Activity>(id);
        }

        public PagedData<Bike_Activity> GetPageData(Pagination page, string keyword)
        {
            var q = this.DbContext.Query<Bike_Activity>().FilterDeleted().WhereIfNotNullOrEmpty(keyword, a => a.Name.Contains(keyword) /*|| a.EnCode.Contains(keyword)*/);

            var pagedData = q.TakePageData(page);
            return pagedData;
        }

    }
}
